home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
PickMeUp.sit
/
Pick Me Up
/
source code
/
Movie app source
/
pickmeUp97
/
source
/
CMoviePane.cp
< prev
next >
Wrap
Text File
|
1997-06-27
|
16KB
|
698 lines
// ===========================================================================
// CMoviePane.cp ©1996-1997 Wootech Corporation. All rights reserved.
// ===========================================================================
/*
Insert Comments Here.
*/
/*
* $Workfile: MyTextEdit.cp $
* $Modtime: 6/20/97 6:18 PM $
* $Revision: 2 $
* $Date: 6/20/97 6:18 PM $
* $History: MyTextEdit.cp $
*/
#include "CMoviePane.h"
#include "MoreFilesExtras.h"
#include <Movies.h>
#include "CTempEventDispatcher.h"
#include "CMovieWind.h"
// ===========================================================================
// •• CMoviePane
// ===========================================================================
CMoviePane::CMoviePane(LStream* inStream) : LView(inStream)
{
//Debugger();
::EnterMovies();
mMoviePtr = nil;
FSSpec theSpec = GetMovieFileSpec();
mMoviePtr = GetMovieFromFile(theSpec);
mPlayIt = false;
}
// ===========================================================================
// •• ~CMoviePane
// ===========================================================================
CMoviePane::~CMoviePane()
{
if(mMoviePtr)
{
::DisposeMovie(mMoviePtr);
}
}
// ===========================================================================
// •• GetMovieFileSpec
// ===========================================================================
FSSpec
CMoviePane::GetMovieFileSpec()
{
// algorithm.
/*
Check for the movie file folder in default directory.
If not there throw error.
Get FSSpec of the directory.
Use dir spec to get the dir id of the directory.
Use that to get the FSSpec of the file named "Pick Me Up Movie"
OSErr = noErr else throw.
return theMovieSpec;
*/
FSSpec spec;
OSErr myErr;
long dirID;
Boolean isDir;
myErr = ::FSMakeFSSpec(0,0, "\pMovie Folder", &spec);
ThrowIfOSErr_(myErr);
myErr = ::FSpGetDirectoryID(&spec, &dirID, &isDir);
ThrowIfOSErr_(myErr);
myErr = ::FSMakeFSSpec(0, dirID, "\pPick Me Up Movie", &spec);
ThrowIfOSErr_(myErr);
return spec;
}
// ===========================================================================
// •• GetMovieFromFile
// ===========================================================================
Movie
CMoviePane::GetMovieFromFile(FSSpec inSpec)
{
/*
Open movie file.
Take inSpec and pass to QuickTime routine to get a Movie from
a file.
return theMovie;
*/
Movie theMovie;
short resRefNum;
OSErr myErr;
short movResID;
Boolean changed;
myErr = ::OpenMovieFile( &inSpec, &resRefNum, fsRdPerm );
ThrowIfOSErr_(myErr);
myErr = NewMovieFromFile( &theMovie,
resRefNum,
&movResID, nil, newMovieActive, &changed);
//Debugger();
ThrowIfOSErr_(myErr);
myErr = ::CloseMovieFile(resRefNum);
//ThrowIfOSErr_(myErr);
return theMovie;
}
// ===========================================================================
// •• DrawSelf
// ===========================================================================
void
CMoviePane::DrawSelf()
{
if(mMoviePtr)
{
//::ShowMoviePoster(mMoviePtr);
Rect thisRect;
::GetMovieBox(mMoviePtr, &thisRect);
short width, height;
width = thisRect.right - thisRect.left;
height = thisRect.bottom - thisRect.top;
thisRect.left = 2;
thisRect.top = 0;
thisRect.bottom = height;
thisRect.right = width;
::DrawPicture(::GetMoviePosterPict(mMoviePtr), &thisRect);
}else DebugStr("\pmMoviePtr is nil.");
}
// ===========================================================================
// •• PlayMovie
// ===========================================================================
void
CMoviePane::PlayMovie()
{
/* simple play function for QuickTime */
/* might be better to redefine this as an LPeriodical SpendTime() or something */
//Debugger();
//Rect frame;
//CalcLocalFrameRect(frame);
// Test code to see if the movies rect has changed since this object was in
// stanciated.
Rect movieRect;
::GetMovieBox(mMoviePtr, &movieRect);
Assert_(::EqualRect(&mRectBuff, &movieRect));
//::OffsetRect(&movieRect, -8, -8);
//::SetMovieBox(mMoviePtr, &movieRect);
//mRectBuff = movieRect;
//FocusDraw();
CTempEventDispatcher theEvent;
//Rect theRect;
//Rect drawRect = {0,0,0,0};
//::GetMovieBox(mMoviePtr, &theRect);
//::SetRect(&drawRect, (frame.left +(frame.right - 5)), (theRect.bottom/2),
// theRect.right, ((theRect.bottom/2) + 5));
mPlayIt = true;
::GoToBeginningOfMovie(mMoviePtr);
::MoviesTask(mMoviePtr, 0);
::StartMovie(mMoviePtr);
//RGBColor red = {65353, 0,0};
//RGBForeColor(&red);
Boolean donePlaying = ::IsMovieDone(mMoviePtr);
Boolean firstTime = true;
while( !donePlaying )
{
::MoviesTask(mMoviePtr, 0); /* keep playing until finished */
//::PaintRect(&drawRect);
//::OffsetRect(&drawRect, -5, 0);
if(!firstTime)
{
theEvent.ProcessTempEvent();
}else{
::FlushEvents(-1, 0);
firstTime = false;
}
if(mPlayIt)
{
donePlaying = ::IsMovieDone(mMoviePtr);
}else{
donePlaying = true;
}
}
this->Refresh();
}
// ===========================================================================
// •• GetMovieFromHandle
// ===========================================================================
Movie
CMoviePane::GetMovieFromHandle(Handle inHandle)
{
}
// ===========================================================================
// •• GetMovieData
// ===========================================================================
Handle
CMoviePane::GetMovieData(FSSpec inSpec)
{
}
// ===========================================================================
// •• ListenToMessage
// ===========================================================================
void
CMoviePane::ListenToMessage(MessageT inMessage, void* ioParam)
{
if(inMessage == kStopPlaying)
mPlayIt = false;
}
// ===========================================================================
// •• ScaleOrCenterMovie
// ==========================================================================
void
CMoviePane::ScaleAndCenterMovie()
{
Movie inMoviePtr = mMoviePtr;
Rect theRect, thisFrame, outDrawRect;
CalcLocalFrameRect(thisFrame);
::GetMovieBox(inMoviePtr, &theRect);
short movieWidth, movieHeight,
thisWidth, thisHeight;
// Getting height and width of the movie rect.
movieWidth = theRect.right - theRect.left;
Assert_((movieWidth > 0));
movieHeight = theRect.bottom - theRect.left;
Assert_((movieHeight > 0));
// Getting the height and width of this' rect.
thisWidth = thisFrame.right - thisFrame.left;
Assert_((thisWidth > 0));
thisHeight = thisFrame.bottom - thisFrame.left;
Assert_((thisHeight > 0));
// Checking which is bigger.
if((movieWidth > thisWidth) || (movieHeight > thisHeight))
{
ScaleDrawRect(theRect, thisFrame, &outDrawRect);
}
else{
outDrawRect = theRect;
}
LocalToPortPoint(topLeft(outDrawRect));
LocalToPortPoint(botRight(outDrawRect));
::SetMovieBox(inMoviePtr, &outDrawRect);
mRectBuff = outDrawRect;
}
//===========================================================================
// •• ScaleDrawRect
//===========================================================================
void
CMoviePane::ScaleDrawRect( Rect inOriginalRect, Rect inThumnailRect,
Rect* outScaledRect)
{
/*
NOTES:
This routine is for scaling the drawRect of a picture to fit into
a thumbnail sized drawing area. For example, if you have a picture
that is 500 x 700 pixels, but only have a 70 x 70 pixel size
area in which to draw the image, this routine will scale
the picture down.
This routine will also scale a rect(outScaledRect) so that it will center
itself in the thumnail. This way, the picture that is scaled down will
be centered when it is drawn in the thumbnail.
Why only Rects?
Generally when drawing pictures, the system routines that do the actual
drawing want a Rect to define the size and location of the picture in the
current GrafPort. that is why all that is needed here is to scale the
rect and then pass outScaledRect to the draw routine.
Rect inOriginalRect; Input the original size of the picture's rect here.
Rect inThumbnailRect; Input the size of the thumnail where the picture is
supposed to be drawn here.
Rect* outScaledRect; This is where the scaled rect for the picture
will be passed back to you.
*/
short percent = 0;
::InsetRect(&inThumnailRect, 1,1);
// Getting the h and w of the orig pics frame size.
short w = inOriginalRect.right - inOriginalRect.left;
short h = inOriginalRect.bottom - inOriginalRect.top;
// Getting the h and w of the thumbs frame size.
short Aw = inThumnailRect.right - inThumnailRect.left;
short Ah = inThumnailRect.bottom - inThumnailRect.top;
// Comparing which is bigger with the orig pics
// Why do we have to compare? In order to scale the picture, we
// need to know which side is bigger. That way, depending on
// which one is bigger, the bigger side will be the full size
// of the thumbnail window, and then we'll scale the other
// side down to match the other side.
if(w > h)
{
// Since the width is larger than the height, we are here.
// We first set the left of inOriginalRect to inThumbnailRects left,
// plus some offset. inThumnailRect was inset by 1, and the offset
// is just found by experimenting.
inOriginalRect.left = inThumnailRect.left + 1;
// Since the width is bigger than the height, we set the
// width to be the size of inThumnailRects width. That way the
// entire width will fit into the thumbnail rect.
inOriginalRect.right = Aw;
// Now we need to know what percentage the image was scaled down.
// We need to know this because we need to scale the other side
// just as much as we scaled the the width.
percent = ((Aw * 100)/w);
// Now we take the percent and determine a pixel amount based on the
// percentage we scaled.
inOriginalRect.bottom = ((percent * h)/100);
// Now we need to center the newly scaled rect in the thumbnail
// rect. If we didn't do this, then the upper left corner of the
// image would be at the upper left corner of the thumbnail. We want
// the image to be in the middle of the thumbnail so we kluge here.
//inOriginalRect.top = ((Ah - inOriginalRect.bottom)/2);
// Just some fudging to get the centering just right. This is found
// with experimentation.
//inOriginalRect.top += 1;
// Since we just collapsed the rect, top down, we need to expand the
// bottom of the rect as much as we collapsed it from top.
//inOriginalRect.bottom += inOriginalRect.top;
}else if(w < h)
{
inOriginalRect.top = inThumnailRect.top + 1;
inOriginalRect.bottom = Ah;
percent = ((Ah * 100)/h);
inOriginalRect.right = ((percent * w)/100);
//inOriginalRect.left = ((Aw - inOriginalRect.right)/2);
//inOriginalRect.left += 2;
//inOriginalRect.right += inOriginalRect.left;
}else if(w == h)
{
InsetRect(&inThumnailRect, 1,1);
inOriginalRect = inThumnailRect;
}
// Now passing the scaled rect back into outScaledRect
::BlockMoveData(&inOriginalRect, outScaledRect, sizeof(Rect));
return;
}
/*
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
// ===========================================================================
// ••
// ===========================================================================
CMoviePane::
{
}
*/